object LoopConditionDemo extends App {
  val bookPrice = 50.0
  val maxFineRate = 0.3
  val maxFine = bookPrice * maxFineRate
  val dailyFine = 0.5

  var overDays = 25
  var totalFine = 0.0

  while (overDays > 0 && totalFine < maxFine) {
    val fineForDay = math.min(dailyFine, maxFine - totalFine)
    totalFine += fineForDay
    overDays -= 1
    println(f"已计算 1 天罚款：$fineForDay%.2f元，累计：$totalFine%.2f元，剩余超期天数：$overDays")
  }

  if (totalFine >= maxFine) {
    println(f"\n已达到最大罚款金额（$maxFine%.2f元），停止计算")
  } else {
    println(s"\n所有超期天数已计算完毕")
  }

  println(f"最终罚款金额：$totalFine%.2f元")
}